﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheOutLetLibrary.Dominio;
using System.Data.OleDb;

namespace TheOutLetLibrary.Infraestrutura {

    class Accessk_freightDAO : BaseDAO, IGenericDAO<k_freight> {

        public Accessk_freightDAO(OleDbTransaction transacao)
            : base(transacao) {
        }

        public int Inclua(k_freight entity) {

            OleDbCommand comando = GetCommand();
            comando.CommandText =
                " INSERT INTO k_freight (" +
                " NR_PEDIDO, [time], amount, discount, totalAmount) " +
                " VALUES (" +
                " @NR_PEDIDO, @time, @amount, @discount, @totalAmount)";
            comando.Parameters.Add("@NR_PEDIDO", OleDbType.Integer).Value = entity.NR_PEDIDO;
            comando.Parameters.Add("@time", OleDbType.VarChar).Value = entity.time.ToString();
            comando.Parameters.Add("@amount", OleDbType.VarChar).Value = entity.amount.ToString();
            comando.Parameters.Add("@discount", OleDbType.VarChar).Value = entity.discount.ToString();
            comando.Parameters.Add("@totalAmount",OleDbType.VarChar).Value = entity.totalAmount.ToString();
            comando.ExecuteNonQuery();

            comando.CommandText = "SELECT @@IDENTITY";
            entity.COD = Convert.ToInt32(comando.ExecuteScalar());
            return entity.COD;

        }

        public k_freight Ache(int Id) {
            throw new NotImplementedException();
        }
    }
}
